package com.xuliugen.demo.multithread.treadlocal;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xuliugen on 2017/11/13.
 */
public class ThreadLocalWeakReferenceGCDemo2 {

    private static final int MAIN_THREAD_LOOP_SIZE = 20;
    private static final int THREAD_LOOP_SIZE = 200;
    private static final int MOCK_DIB_DATA_LOOP_SIZE = 2000000;

    public static void main(String[] args) throws InterruptedException {

        try {
            //等待连接JConsole
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 1; i < MAIN_THREAD_LOOP_SIZE; i++) {
            ThreadLocal<Map<Integer, String>> threadLocal = new ThreadLocal<>();
            Map<Integer, String> map = new HashMap<>();
            map.put(i, "我是第" + i + "个ThreadLocal数据！");
            threadLocal.set(map);
            threadLocal.get();

            if (i == MAIN_THREAD_LOOP_SIZE - 1) {
                threadLocal.get();
            }
            System.out.println("第" + i + "次获取ThreadLocal中的数据");
            Thread.sleep(1000);
        }
    }
}
